<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <form>
        <input type="text" name="user" />
        <input type="text" name="age" />
        <button type="submit">提交</button>
    </form>
</body>

</html>
<script src="./js/jquery-3.6.1.min.js"></script>
<script>

    $('form').on('submit', function (e) {
        e.preventDefault()
        $.post('/api/login', {
            user: $('input').eq(0).val(),
            age: $('input').eq(1).val(),
        }, (res) => {
            if (res.status == 0) {
                window.location.href = "/index.html";
            } else if (res.status == 1) {
                alert('用户名或者密码错误')
            }
        })

    })
</script>